<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: wjk
 * @LastEditTime: 2020-11-03 13:56:25
 * @description: file content
 -->
<template>
  <base-page-view class-name="page-container earnings-page">
    <view v-if="isShow" class="box">
      <view class="title">
        零售收益
        <image src="/static/images/mine/question.png" class="questionIcon" @click="question(1)" />
      </view>
      <view class="content">
        <view class="c_top">
          <view>
            <view>累计收益(元)</view>
            <view class="totalPrice">{{ myEarnings.total | formatMoney }}</view>
          </view>
          <view class="btn" @click="$navigateTo('/pagesCommission/earnings/index')">
            <image src="/static/images/mine/icon_vip_list.png" class="questionIcon" @click="question(2)" />
            查看明细
          </view>
        </view>
        <view class="c_border"></view>
        <view class="c_bottom">
          <view>
            <view class="text">累计已发放</view>
            <view class="price">{{ myEarnings.withdraw | formatMoney }}</view>
          </view>
          <view class="border"></view>
          <view>
            <view class="text">今日预估收益</view>
            <view class="price">{{ myEarnings.today | formatMoney }}</view>
          </view>
          <view class="border"></view>
          <view>
            <view class="text">本月预估收益</view>
            <view class="price">{{ myEarnings.currentMonth | formatMoney }}</view>
          </view>
          <!-- <view>
            <view class="price">{{ myEarnings.unWithdraw | formatMoney }}</view>
            <view class="text">待确认(元)</view>
          </view> -->
        </view>
      </view>
    </view>
    <view v-if="isShow" class="box">
      <view class="title">
        箱起收益
        <image src="/static/images/mine/question.png" class="questionIcon" @click="question(2)" />
      </view>
      <view class="content boxBg" @click="box_plan">
        <view class="c_top">
          <view>
            <!-- <view class="text">累计折扣(元)</view> -->
            <view class="text">累计收益积分</view>
            <!-- <view v-if="box.earningTotal >= 0" class="totalPrice">{{ box.earningTotal | formatMoney }}</view>
            <view v-else class="totalPrice totalPriceRed">{{ Math.abs(box.earningTotal) | formatMoney }}</view> -->
            <view v-if="box_income.all_integral >= 0" class="totalPrice">{{ box_income.all_integral | formatMoney }}</view>
            <view v-else class="totalPrice totalPriceRed">{{ Math.abs(box_income.all_integral) | formatMoney }}</view>
          </view>
          <view class="btn boxBtn" @click.stop="box_plan"><!-- $navigateTo('/pagesCommission/box/index') -->
            <image src="/static/images/mine/icon_vip_list.png" class="questionIcon" />
            查看明细
          </view>
        </view>
        <view class="c_border"></view>
        <view class="c_bottom b_bottom">
          <view>
            <view class="text">累计核销</view>
            <view class="price">{{ box_income.total_write_off | formatMoney }}</view>
          </view>
          <view class="border b_second"></view>
          <view class="b_second">
            <view class="text">本月收益</view>
            <view v-if="box_income.month_integral >= 0" class="price">{{ box_income.month_integral | formatMoney }}</view>
            <view v-else class="price totalPriceRed">{{ Math.abs(box_income.month_integral) | formatMoney }}</view>
          </view>
        </view>
      </view>
    </view>
    <view v-if="isShow" class="box">
      <view class="title">
        箱起折扣
        <image src="/static/images/mine/question.png" class="questionIcon" @click="question(4)" />
      </view>
      <view class="content boxBg">
        <view class="c_top">
          <view>
            <view class="text">累计折扣(元)</view>
            <view v-if="box.earningTotal >= 0" class="totalPrice">{{ box.earningTotal | formatMoney }}</view>
            <view v-else class="totalPrice totalPriceRed">{{ Math.abs(box.earningTotal) | formatMoney }}</view>
          </view>
          <view class="btn boxBtn" @click="$navigateTo('/pagesCommission/box/index')">
            <image src="/static/images/mine/icon_vip_list.png" class="questionIcon" @click="question(4)" />
            查看明细
          </view>
        </view>
        <view class="c_border"></view>
        <view class="c_bottom b_bottom">
          <!-- <view>
            <view class="text">预估普通返利(元)</view>
            <view class="price">{{ box.personalMoney | formatMoney }}</view>

          </view>
          <view class="b_second">
            <view class="text">预估活动返利(元)</view>
            <view class="price">{{ box.teamMoneyField | formatMoney }}</view>

          </view> -->
          <!-- <view>
            <view class="text">累计已发放</view>
            <view class="price">{{ box.withdrawTotal | formatMoney }}</view>
          </view>
          <view class="border"></view> -->
          <view>
            <view class="text">本月自购箱数</view>
            <view class="price">{{ box.personalBoxNumber | formatMoney }}</view>
          </view>
          <view class="border b_second"></view>
          <view class="b_second">
            <view class="text">本月自购折扣</view>
            <view v-if="box.personalMoney >= 0" class="price">{{ box.personalMoney | formatMoney }}</view>
            <view v-else class="price totalPriceRed">{{ Math.abs(box.personalMoney) | formatMoney }}</view>
          </view>

        </view>
      </view>
    </view>
    <view class="box">
      <view class="title">
        碧划算收益
        <image src="/static/images/mine/question.png" class="questionIcon" @click="question(3)" />
      </view>
      <view class="content bihsBg">
        <view class="c_top">
          <view>
            <view class="text">累计收益(元)</view>
            <view class="totalPrice">{{ bihs.totalFee | formatMoney }}</view>
          </view>
          <view class="btn bihsBtn" @click="$navigateTo('/pagesCommission/bihs/index')">
            <image src="/static/images/mine/icon_vip_list.png" class="questionIcon" @click="question(2)" />
            查看明细
          </view>
        </view>
        <view class="c_border"></view>
        <view class="c_bottom">
          <view>
            <view class="text">累计已提现</view>
            <view class="price">{{ bihs.takeFee | formatMoney }}</view>
          </view>
          <view class="border"></view>
          <view class="b_second">
            <view class="text">今日预估收益</view>
            <view class="price">{{ bihs.todayFee | formatMoney }}</view>
          </view>
          <view class="border"></view>
          <view class="b_second">
            <view class="text">本月预估收益</view>
            <view class="price">{{ bihs.currentMonthFee | formatMoney }}</view>
          </view>
        </view>
      </view>
    </view>
    <confirm-popup ref="confirm" />
  </base-page-view>
</template>

<script>
import './index.scss'
import confirmPopup from '@/components/confirmPopup/index'
import { inApp } from '@/utils/tools'
import { mapState } from 'vuex'
export default {
  components: {
    confirmPopup
  },
  data() {
    return {
      myEarnings: {},
      box: {},
      box_income: {},
      show: true,
      message: '',
      messageT: '',
      bihs: {}
    }
  },
  computed: {
    ...mapState([
      'token'
    ]),
    isShow() {
      if (this.$store.state.setting.show_withdraw === 1) {
        return true
      } else {
        return false
      }
    }
  },
  created() {
  },
  onLoad(option) {
  },
  onReady() {
    this.certificationGet()
    this.init()
  },
  methods: {
    box_plan() {
      // #ifdef H5
      if (this.$Bridge.isInApp) {
        this.$Bridge.callHandler({
          type: 'mybox'
        }, async(res) => {
          console.log('app params:', res)
        })
      } else {
        uni.showToast({
          title: '仅APP支持查看，请下载APP',
          duration: 2000,
          icon: 'none'
        })
      }
      // #endif
      // #ifdef MP-WEIXIN
      uni.showToast({
        title: '仅APP支持查看，请下载APP',
        duration: 2000,
        icon: 'none'
      })
      // #endif
    },
    async certificationGet() {
      if (this.$store.state.setting) {
        if (this.$store.state.setting.status !== 3) {
          // 判断是否在app,在app不弹框,用原生的弹框
          if (inApp()) {
            return false
          } else {
            const real = await this.$api.commissionApi.certificationQuery()
            if (real.code === 0) {
              if (real.data) {
                if (real.data.status !== 3) {
                  this.$refs.confirm.show({
                    title: '提示',
                    content: '您还未进行实名认证，只有实名认证的用户才可以发起提现',
                    yesCb: async() => {
                      uni.removeStorageSync('realName')
                      this.$navigateTo('/pagesMine/certification/index')
                    }
                  })
                }
              }
            }
          }
        }
      }
    },
    async app_interactive_data() {
      const earnings = await this.$api.commissionApi.getUserEarning({ userId: this.$store.state.userInfo.uid })
      if (earnings.code === '000000') {
        this.myEarnings = earnings.data
      }
      const boxData = await this.$api.commissionApi.getUserSummaryInfo({ userId: this.$store.state.userInfo.uid })
      if (boxData.code === '000000') {
        this.box = boxData.data
        console.log('this.box', this.box)
      }
      const bihsData = await this.$api.commissionApi.getBihsCommission({ userId: this.$store.state.userInfo.uid })
      if (bihsData.code === '000000') {
        this.bihs = bihsData.data
        console.log('this.bihs', this.bihs)
      }
      const data = await this.$api.boxApi.integralInfo()
      if (data.code === 0) {
        console.log(data)
        this.box_income = data.data
      }
    },
    question(type) {
      let message = ''
      let title = ''
      if (type === 1) {
        message = '零售收益：指自购碧选零售类商品，所得收益。' +
       '<br/>1、累计已发放：指累计发放的碧选零售收益总和。' +
       '<br/>2、今日预估收益：指根据“今日商品销售情况”产生的预估收益。' + '<br/>3、本月预估收益：指根据“本月商品销售情况”产生的预估收益。'
        title = '说明'
      } else if (type === 2) {
        message = '箱起收益：指自购碧选批发类商品，所得奖励积分<br/>' +
        '1.累计收益：累计购买箱起商品，所得的奖励积分<br/>' +
        '2.本月收益：本月购买箱起商品，所得的奖励积分<br/>' +
        '3.累计核销：累计已核销的总积分.'
        title = '说明'
      } else if (type === 3) {
        message = '碧划算收益：指自购淘宝联盟、多多进宝、京东联盟、唯品会联盟商品，所得收益。' +
        '<br/>1、累计已发放：指累计已提现的收益金额总和。' + '<br/>2、今日预估收益：指根据“今日商品销售情况”产生的碧划算预估收益。' +
        '<br/>3、本月预估收益：指根据“本月商品销售情况”产生的碧划算预估收益。'
        title = '说明'
      } else if (type === 4) {
        message = '箱起折扣：指自购碧选批发类商品，所得折扣。' +
        '<br/>1、累计已发放：指累计发放的箱起折扣总和。' + '<br/>2、本月自购箱数：指本月自购的箱起商品数量。' +
        '<br/>3、本月预估折扣：指根据“本月箱起商品销售情况”产生的预估折扣。' +
        '<br/>4、红色字体：本月自购折扣为负数。'
        title = '说明'
      }
      this.message =
      this.$gc.$message({
        content: message,
        type: 'richText',
        title: title,
        showMessage: true,
        showCancel: false,
        confirmText: '好哒',
        align: 'left'
      })
    }
  }
}
</script>
